package standard;

import standard.util.Utils;

import java.util.LinkedList;
import java.util.List;

/**
 * Create by Lingo
 */

public class TableInfo {
    private String name;

    private List<ColumnInfo> columnInfoList = new LinkedList<>();

    private String remark;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public List<ColumnInfo> getColumnInfoList() {
        return columnInfoList;
    }

    public void setColumnInfoList(List<ColumnInfo> columnInfoList) {
        this.columnInfoList = columnInfoList;
    }

    public StandardVar getPrimaryKey(){
        //todo : 目前只取第一个主键
        for (ColumnInfo columnInfo : columnInfoList) {
            if (columnInfo.getIsPrimary() == 1){
                return Utils.colInfo2StandardVar(columnInfo);
            }
        }
        return null;
    }

    public List<StandardVar> getOtherField() {
        List<StandardVar> otherField = new LinkedList<>();
        for (ColumnInfo columnInfo : columnInfoList) {
            if (columnInfo.getIsPrimary() == 1) {
                continue;
            }
            otherField.add(Utils.colInfo2StandardVar(columnInfo));
        }
        return otherField;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public ColumnInfo getPrimaryCol(){
        for (ColumnInfo columnInfo : columnInfoList) {
            if (columnInfo.getIsPrimary() == 1){
                return columnInfo;
            }
        }
        return null;
    }

    public List<ColumnInfo> getOtherFieldCol() {
        List<ColumnInfo> otherField = new LinkedList<>();
        for (ColumnInfo columnInfo : columnInfoList) {
            if (columnInfo.getIsPrimary() == 1) {
                continue;
            }
            otherField.add(columnInfo);
        }
        return otherField;
    }
}
